#include "stdafx.h"
#include "RequestsManager.h"


// static
std::map<std::wstring, RequestWorker*> RequestsManager::groupedWorkers;

// static
void RequestsManager::run(const SqlRequest &request)
{
	RequestWorker *worker = 0;

	if ( request.groupId.empty() )
	{
		worker = new RequestWorker(true);
	}
	else
	{
		if ( groupedWorkers.find(request.groupId) == groupedWorkers.end() )
		{
			groupedWorkers[request.groupId] = worker = new RequestWorker(false);
		}
		else
		{
			worker = groupedWorkers[request.groupId];
		}
	}

	assert(worker);

	worker->pushRequest(request);
}
